import tkinter as tk

def calculate():
    S_tank = float(entry_S_tank.get())
    H = float(entry_H.get())
    D_g = float(entry_D_g.get())
    miu = float(entry_miu.get())

    v = 1 / (1 + miu) ** 0.5 * (2 * 9.81 * H) ** 0.5
    t = 2 * S_tank * H / v / ((3.14159 * D_g ** 2) / 4 / 1000000)

    label_v.config(text="水流速度: {:.2f} m/s".format(v))
    label_t.config(text="排水时间: {:.2f} 秒".format(t))

# 创建主窗口
window = tk.Tk()
window.title("池子排水计算器")

# 创建标签和输入框
label_S_tank = tk.Label(window, text="输入池子表面积(m2):")
label_S_tank.pack()
entry_S_tank = tk.Entry(window)
entry_S_tank.pack()

label_H = tk.Label(window, text="输入有效水深(m):")
label_H.pack()
entry_H = tk.Entry(window)
entry_H.pack()

label_D_g = tk.Label(window, text="输入排水管管径(mm):")
label_D_g.pack()
entry_D_g = tk.Entry(window)
entry_D_g.pack()

label_miu = tk.Label(window, text="输入沿程和局部水头损失系数:")
label_miu.pack()
entry_miu = tk.Entry(window)
entry_miu.pack()

# 创建计算按钮
button_calculate = tk.Button(window, text="计算", command=calculate)
button_calculate.pack()

# 创建结果标签
label_v = tk.Label(window, text="水流速度: ")
label_v.pack()
label_t = tk.Label(window, text="排水时间: ")
label_t.pack()

# 运行主循环
window.mainloop()